home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-01 | 55.5 KB | 1,319 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i092: gnucalc - GNU Emacs Calculator, v2.00, Part44/56
- Message-ID: <1991Nov1.183754.21020@sparky.imd.sterling.com>
- X-Md4-Signature: 0969d0f8e53ab4b5855eadb3d104aa96
- Date: Fri, 1 Nov 1991 18:37:54 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 92
- Archive-name: gnucalc/part44
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 44; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- error form. This includes the estimated error associated with
- the mean. If the inputs are error forms, the error is the square
- root of the reciprocal of the sum of the reciprocals of the squares
- of the input errors. (I.e., the variance is the reciprocal of the
- sum of the reciprocals of the variances.)
- @tex
- \turnoffactive
- $$ \sigma_\mu^2 = {1 \over \displaystyle \sum {1 \over \sigma_i^2}} $$
- @end tex
- If the inputs are plain
- numbers, the error is equal to the standard deviation of the values
- divided by the square root of the number of values. (This works
- out to be equivalent to calculating the standard deviation and
- then assuming each value's error is equal to this standard
- deviation.)@refill
- @tex
- \turnoffactive
- $$ \sigma_\mu = {\sigma \over \sqrt N} $$
- @end tex
- X
- @kindex H u M
- @pindex calc-vector-median
- @tindex vmedian
- @cindex Median of data values
- The @kbd{H u M} (@code{calc-vector-median}) [@code{vmedian}]
- command computes the median of the data values. The values are
- first sorted into numerical order; the median is the middle
- value after sorting. (If the number of data values is even,
- the median is taken to be the average of the two middle values.)
- The median function is different from the other functions in
- this section in that the arguments must all be real numbers;
- variables are not accepted even when nested inside vectors.
- (Otherwise it is not possible to sort the data values.) If
- any of the input values are error forms, their error parts are
- ignored.
- X
- The median function also accepts distributions. For both normal
- (error form) and uniform (interval) distributions, the median is
- the same as the mean.
- X
- @kindex H I u M
- @pindex calc-vector-harmonic-mean
- @tindex vhmean
- @cindex Harmonic mean
- The @kbd{H I u M} (@code{calc-vector-harmonic-mean}) [@code{vhmean}]
- command computes the harmonic mean of the data values. This is
- defined as the reciprocal of the arithmetic mean of the reciprocals
- of the values.
- @tex
- \turnoffactive
- $$ { N \over \displaystyle \sum {1 \over x_i} } $$
- @end tex
- X
- @kindex u G
- @pindex calc-vector-geometric-mean
- @tindex vgmean
- @cindex Geometric mean
- The @kbd{u G} (@code{calc-vector-geometric-mean}) [@code{vgmean}]
- command computes the geometric mean of the data values. This
- is the @i{N}th root of the product of the values. This is also
- equal to the @code{exp} of the arithmetic mean of the logarithms
- of the data values.
- @tex
- \turnoffactive
- $$ \exp \left ( \sum { \ln x_i } \right ) =
- X \left ( \prod { x_i } \right)^{1 / N} $$
- @end tex
- X
- @kindex H u G
- @tindex agmean
- The @kbd{H u G} [@code{agmean}] command computes the ``arithmetic-geometric
- mean'' of two numbers taken from the stack. This is computed by
- replacing the two numbers with their arithmetic mean and geometric
- mean, then repeating until the two values converge.
- @tex
- \turnoffactive
- $$ a_{i+1} = { a_i + b_i \over 2 } , \qquad b_{i+1} = \sqrt{a_i b_i} $$
- @end tex
- X
- @cindex Root-mean-square
- Another commonly used mean, the RMS (root-mean-square), can be computed
- for a vector of numbers simply by using the @kbd{A} command.
- X
- @kindex u S
- @pindex calc-vector-sdev
- @tindex vsdev
- @cindex Standard deviation
- @cindex Sample statistics
- The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command
- computes the standard deviation@c{ $\sigma$}
- @asis{ }of the data values. If the
- values are error forms, the errors are used as weights just
- as for @kbd{u M}. This is the @emph{sample} standard deviation,
- whose value is the square root of the sum of the squares of the
- differences between the values and the mean of the @cite{N} values,
- divided by @cite{N-1}.
- @tex
- \turnoffactive
- $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$
- @end tex
- X
- This function also applies to distributions. The standard deviation
- of a single error form is simply the error part. The standard deviation
- of a continuous interval happens to equal the difference between the
- limits, divided by @c{$\sqrt{12}$}
- @cite{sqrt(12)}. The standard deviation of an
- integer interval is the same as the standard deviation of a vector
- of those integers.
- X
- @kindex I u S
- @pindex calc-vector-pop-sdev
- @tindex vpsdev
- @cindex Population statistics
- The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}]
- command computes the @emph{population} standard deviation.
- It is defined by the same formula as above but dividing
- by @cite{N} instead of by @cite{N-1}. The population standard
- deviation is used when the input represents the entire set of
- data values in the distribution; the sample standard deviation
- is used when the input represents a sample of the set of all
- data values, so that the mean computed from the input is itself
- only an estimate of the true mean.
- @tex
- \turnoffactive
- $$ \sigma^2 = {1 \over N} \sum (x_i - \mu)^2 $$
- @end tex
- X
- For error forms and continuous intervals, @code{vpsdev} works
- exactly like @code{vsdev}. For integer intervals, it computes the
- population standard deviation of the equivalent vector of integers.
- X
- @kindex H u S
- @kindex H I u S
- @pindex calc-vector-variance
- @pindex calc-vector-pop-variance
- @tindex vvar
- @tindex vpvar
- @cindex Variance of data values
- The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and
- @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}]
- commands compute the variance of the data values. The variance
- is the square@c{ $\sigma^2$}
- @asis{ }of the standard deviation, i.e., the sum of the
- squares of the deviations of the data values from the mean.
- (This definition also applies when the argument is a distribution.)
- X
- @tindex vflat
- The @code{vflat} algebraic function returns a vector of its
- arguments, interpreted in the same way as the other functions
- in this section. For example, @samp{vflat(1, [2, [3, 4]], 5)}
- returns @samp{[1, 2, 3, 4, 5]}.
- X
- @node Paired-Sample Statistics, , Single-Variable Statistics, Statistical Operations
- @subsection Paired-Sample Statistics
- X
- @noindent
- The functions in this section take two arguments, which must be
- vectors of equal size. The vectors are each flattened in the same
- way as by the single-variable statistical functions. Given a numeric
- prefix argument of 1, these functions instead take one object from
- the stack, which must be an @c{$N\times2$}
- @asis{Nx2} matrix of data values. Once
- again, variable names can be used in place of actual vectors and
- matrices.
- X
- @kindex u C
- @pindex calc-vector-covariance
- @tindex vcov
- @cindex Covariance
- The @kbd{u C} (@code{calc-vector-covariance}) [@code{vcov}] command
- computes the sample covariance of two vectors. The covariance
- of vectors @var{x} and @var{y} is the sum of the products of the
- differences between the elements of @var{x} and the mean of @var{x}
- times the differences between the corresponding elements of @var{y}
- and the mean of @var{y}, all divided by @cite{N-1}. Note that
- the variance of a vector is just the covariance of the vector
- with itself. Once again, if the inputs are error forms the
- errors are used as weight factors. If both @var{x} and @var{y}
- are composed of error forms, the error for a given data point
- is taken as the square root of the sum of the squares of the two
- input errors.
- @tex
- \turnoffactive
- $$ \sigma_{x\!y}^2 = {1 \over N-1} \sum (x_i - \mu_x) (y_i - \mu_y) $$
- $$ \sigma_{x\!y}^2 =
- X {\displaystyle {1 \over N-1}
- X \sum {(x_i - \mu_x) (y_i - \mu_y) \over \sigma_i^2}
- X \over \displaystyle {1 \over N} \sum {1 \over \sigma_i^2}}
- $$
- @end tex
- X
- @kindex I u C
- @pindex calc-vector-pop-covariance
- @tindex vpcov
- The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}]
- command computes the population covariance, which is the same as the
- sample covariance computed by @kbd{u C} except dividing by @cite{N}
- instead of @cite{N-1}.
- X
- @kindex H u C
- @pindex calc-vector-correlation
- @tindex vcorr
- @cindex Correlation coefficient
- @cindex Linear correlation
- The @kbd{H u C} (@code{calc-vector-correlation}) [@code{vcorr}]
- command computes the linear correlation coefficient of two vectors.
- This is defined by the covariance of the vectors divided by the
- product of their standard deviations. (There is no difference
- between sample or population statistics here.)
- @tex
- \turnoffactive
- $$ r_{x\!y} = { \sigma_{x\!y}^2 \over \sigma_x^2 \sigma_y^2 } $$
- @end tex
- X
- @node Reducing and Mapping, Vector and Matrix Formats, Statistical Operations, Matrix Functions
- @section Reducing and Mapping Vectors
- X
- @noindent
- The commands in this section allow for more general operations on the
- elements of vectors.
- X
- @kindex V A
- @pindex calc-apply
- @tindex apply
- The simplest of these operations is @kbd{V A} (@code{calc-apply})
- [@code{apply}], which applies a given operator to the elements of a vector.
- For example, applying the hypothetical function @code{f} to the vector
- @samp{[1, 2, 3]} would produce the function call @samp{f(1, 2, 3)}.
- Applying the @code{+} function to the vector @samp{[a, b]} gives
- @samp{a + b}. Applying @code{+} to the vector @samp{[a, b, c]} is an
- error, since the @code{+} function expects exactly two arguments.
- X
- While @kbd{V A} is useful in some cases, you will usually find that either
- @kbd{V R} or @kbd{V M}, described below, is closer to what you want.
- X
- @menu
- * Specifying Operators::
- * Mapping::
- * Reducing::
- * Nesting and Fixed Points::
- * Generalized Products::
- @end menu
- X
- @node Specifying Operators, Mapping, Reducing and Mapping, Reducing and Mapping
- @subsection Specifying Operators
- X
- @noindent
- Commands in this section (like @kbd{V A}) prompt you to press the key
- corresponding to the desired operator. Press @kbd{?} for a partial
- list of the available operators. Generally, an operator is any key or
- sequence of keys that would normally take one or more arguments from
- the stack and replace them with a result. For example, @kbd{V A H C}
- uses the hyperbolic cosine operator, @code{cosh}. (Since @code{cosh}
- expects one argument, @kbd{V A H C} requires a vector with a single
- element as its argument.)
- X
- You can press @kbd{x} at the operator prompt to select any algebraic
- function by name to use as the operator. This includes functions you
- have defined yourself using the @kbd{Z F} command. (@xref{Algebraic
- Definitions}.) If you give a name for which no function has been
- defined, the result is left in symbolic form, as in @samp{f(1, 2, 3)}.
- Calc will prompt for the number of arguments the function takes if it
- can't figure it out on its own (say, because you named a function that
- is currently undefined). It is also possible to type a digit key before
- the function name to specify the number of arguments, e.g.,
- @kbd{V M 3 x f RET} calls @code{f} with three arguments even if it
- looks like it ought to have only two. This technique may be necessary
- if the function allows a variable number of arguments. For example,
- the @kbd{v e} [@code{vexp}] function accepts two or three arguments;
- if you want to map with the three-argument version, you will have to
- type @kbd{V M 3 v e}.
- X
- It is also possible to apply any formula to a vector by treating that
- formula as a function. When prompted for the operator to use, press
- @kbd{'} (the apostrophe) and type your formula as an algebraic entry.
- You will then be prompted for the argument list, which defaults to a
- list of all variables that appear in the formula, sorted into alphabetic
- order. For example, suppose you enter the formula @samp{x + 2y^x}.
- The default argument list would be @samp{(x y)}, which means that if
- this function is applied to the arguments @samp{[3, 10]} the result will
- be @samp{3 + 2*10^3}. (If you plan to use a certain formula in this
- way often, you might consider defining it as a function with @kbd{Z F}.)
- X
- Another way to specify the arguments to the formula you enter is with
- @kbd{$}, @kbd{$$}, and so on. For example, @kbd{V A ' $$ + 2$^$$}
- has the same effect as the previous example. The argument list is
- automatically taken to be @samp{($$ $)}. (The order of the arguments
- may seem backwards, but it is analogous to the way normal algebraic
- entry interacts with the stack.)
- X
- If you press @kbd{$} at the operator prompt, the effect is similar to
- the apostrophe except that the relevant formula is taken from top-of-stack
- instead. The actual vector arguments of the @kbd{V A $} or related command
- then start at the second-to-top stack position. You will still be
- prompted for an argument list.
- X
- @cindex Nameless functions
- @cindex Generic functions
- A function can be written without a name using the notation @samp{<#1 - #2>},
- which means ``a function of two arguments that computes the first
- argument minus the second argument.'' The symbols @samp{#1} and @samp{#2}
- are placeholders for the arguments. You can use any names for these
- placeholders if you wish, by including an argument list followed by a
- colon: @samp{<x, y : x - y>}. When you type @kbd{V M ' $$ + 2$^$$ RET},
- Calc builds the nameless function @samp{<#1 + 2 #2^#1>} as the function
- to map across the vectors. When you type @kbd{V M ' x + 2y^x RET RET},
- Calc builds the nameless function @samp{<x, y : x + 2 y^x>}. In both
- cases, Calc also writes the nameless function to the Trail so that you
- can get it back later if you wish.
- X
- If there is only one argument, you can write @samp{#} in place of @samp{#1}.
- (Note that @samp{< >} notation is also used for date forms. Calc tells
- that @samp{<@var{stuff}>} is a nameless function by the presence of
- @samp{#} signs inside @var{stuff}, or by the fact that @var{stuff}
- begins with a list of variables followed by a colon.)
- X
- You can type a nameless function directly to @kbd{V M '}, or put one on
- the stack and use it with @kbd{V M $}. Calc will not prompt for an
- argument list in this case, since the nameless function specifies the
- argument list as well as the function itself. In @kbd{V M '}, you can
- omit the @samp{< >} marks if you use @samp{#} notation for the arguments,
- so that @kbd{V M ' #1+#2 RET} is the same as @kbd{V M ' <#1+#2> RET},
- which in turn is the same as @kbd{V M ' $$+$ RET}.
- X
- @cindex Lambda expressions
- @tindex lambda
- The internal format for @samp{<x, y : x + y>} is @samp{lambda(x, y, x + y)}.
- (The word @code{lambda} derives from Lisp notation and the theory of
- functions.) The internal format for @samp{<#1 + #2>} is @samp{lambda(ArgA,
- ArgB, ArgA + ArgB)}. Note that there is no actual Calc function called
- @code{lambda}; the whole point is that the @code{lambda} expression is
- used in its symbolic form, not evaluated for an answer until it is applied
- to specific arguments by a command like @kbd{V A} or @kbd{V M}.
- X
- (Actually, @code{lambda} does have one special property: Its arguments
- are never evaluated; for example, putting @samp{<(2/3) #>} on the stack
- will not simplify the @samp{2/3} until the nameless function is actually
- called.)
- X
- @tindex add
- @tindex sub
- @tindex mul
- @tindex div
- @tindex pow
- @tindex neg
- @tindex mod
- @tindex vconcat
- As usual, commands like @kbd{V A} have algebraic function name equivalents.
- For example, @kbd{V A k g} with an argument of @samp{v} is equivalent to
- @samp{apply(gcd, v)}. The first argument specifies the operator name,
- and is either a variable whose name is the same as the function name,
- or a nameless function like @samp{<#^3+1>}. Operators that are normally
- written as algebraic symbols have the names @code{add}, @code{sub},
- @code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and
- @code{vconcat}.@refill
- X
- @tindex call
- The @code{call} function builds a function call out of several arguments:
- @samp{call(gcd, x, y)} is the same as @samp{apply(gcd, [x, y])}, which
- in turn is the same as @samp{gcd(x, y)}. The first argument of @code{call},
- like the other functions described here, may be either a variable naming a
- function, or a nameless function (@samp{call(<#1+2#2>, x, y)} is the same
- as @samp{x + 2y}).
- X
- (Experts will notice that it's not quite proper to use a variable to name
- a function, since the name @code{gcd} corresponds to the Lisp variable
- @code{var-gcd} but to the Lisp function @code{calcFunc-gcd}. Calc
- automatically makes this translation, so you don't have to worry
- about it.)
- X
- @node Mapping, Reducing, Specifying Operators, Reducing and Mapping
- @subsection Mapping
- X
- @noindent
- @kindex V M
- @pindex calc-map
- @tindex map
- The @kbd{V M} (@code{calc-map}) [@code{map}] command applies a given
- operator elementwise to one or more vectors. For example, mapping
- @code{A} [@code{abs}] produces a vector of the absolute values of the
- elements in the input vector. Mapping @code{+} pops two vectors from
- the stack, which must be of equal length, and produces a vector of the
- pairwise sums of the elements. If either argument is a non-vector, it
- is duplicated for each element of the other vector. For example,
- @kbd{[1,2,3] 2 V M ^} squares the elements of the specified vector.
- With the 2 listed first, it would have computed a vector of powers of
- two. Mapping a user-defined function pops as many arguments from the
- stack as the function requires. If you give an undefined name, you will
- be prompted for the number of arguments to use.@refill
- X
- If any argument to @kbd{V M} is a matrix, the operator is normally mapped
- across all elements of the matrix. For example, given the matrix
- @cite{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to
- produce another @c{$3\times2$}
- @asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}.
- X
- @tindex mapr
- The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the
- operator prompt) maps by rows instead. For example, @kbd{V M _ A} views
- the above matrix as a vector of two 3-element row vectors. It produces
- a new vector which contains the absolute values of those row vectors,
- namely @cite{[3.74, 8.77]}. (Recall, the absolute value of a vector is
- defined as the square root of the sum of the squares of the elements.)
- Some operators accept vectors and return new vectors; for example,
- @kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row
- of the matrix to get a new matrix, @cite{[[3, -2, 1], [-6, 5, -4]]}.
- X
- Sometimes a vector of vectors (representing, say, strings, sets, or lists)
- happens to look like a matrix. If so, remember to use @kbd{V M _} if you
- want to map a function across the whole strings or sets rather than across
- their individual elements.
- X
- @tindex mapc
- The command @kbd{V M :} [@code{mapc}] maps by columns. Basically, it
- transposes the input matrix, maps by rows, and then, if the result is a
- matrix, transposes again. For example, @kbd{V M : A} takes the absolute
- values of the three columns of the matrix, treating each as a 2-vector,
- and @kbd{V M : v v} reverses the columns to get the matrix
- @cite{[[-4, 5, -6], [1, -2, 3]]}.
- X
- (The symbols @kbd{_} and @kbd{:} were chosen because they had row-like
- and column-like appearances, and were not already taken by useful
- operators. Also, they appear shifted on most keyboards so they are easy
- to type after @kbd{V M}.)
- X
- The @kbd{_} and @kbd{:} modifiers have no effect on arguments that are
- not matrices (so if none of the arguments are matrices, they have no
- effect at all). If some of the arguments are matrices and others are
- plain numbers, the plain numbers are held constant for all rows of the
- matrix (so that @kbd{2 V M _ ^} squares every row of a matrix; squaring
- a vector takes a dot product of the vector with itself).
- X
- If some of the arguments are vectors with the same lengths as the
- rows (for @kbd{V M _}) or columns (for @kbd{V M :}) of the matrix
- arguments, those vectors are also held constant for every row or
- column.
- X
- Sometimes it is useful to specify another mapping command as the operator
- to use with @kbd{V M}. For example, @kbd{V M _ V A +} applies @kbd{V A +}
- to each row of the input matrix, which in turn adds the two values on that
- row. If you give another vector-operator command as the operator for
- @kbd{V M}, it automatically uses map-by-rows mode if you don't specify
- otherwise; thus @kbd{V M V A +} is equivalent to @kbd{V M _ V A +}. (If
- you really want to map-by-elements another mapping command, you can use
- a triple-nested mapping command: @kbd{V M V M V A +} means to map
- @kbd{V M V A +} over the rows of the matrix; in turn, @kbd{V A +} is
- mapped over the elements of each row.)
- X
- @tindex mapa
- @tindex mapd
- Previous versions of Calc had ``map across'' and ``map down'' modes
- that are now considered obsolete; the old ``map across'' is now simply
- @kbd{V M V A}, and ``map down'' is now @kbd{V M : V A}. The algebraic
- functions @code{mapa} and @code{mapd} are still supported, though.
- Note also that, while the old mapping modes were persistent (once you
- set the mode, it would apply to later mapping commands until you reset
- it), the new @kbd{:} and @kbd{_} modifiers apply only to the current
- mapping command. The default @kbd{V M} always means map-by-elements.
- X
- @xref{Algebraic Manipulation}, for the @kbd{a M} command, which is like
- @kbd{V M} but for equations and inequalities instead of vectors.
- @xref{Storing Variables}, for the @kbd{s m} command which modifies a
- variable's stored value using a @kbd{V M}-like operator.
- X
- @node Reducing, Nesting and Fixed Points, Mapping, Reducing and Mapping
- @subsection Reducing
- X
- @noindent
- @kindex V R
- @pindex calc-reduce
- @tindex reduce
- The @kbd{V R} (@code{calc-reduce}) [@code{reduce}] command applies a given
- binary operator across all the elements of a vector. A binary operator is
- a function such as @code{+} or @code{max} which takes two arguments. For
- example, reducing @code{+} over a vector computes the sum of the elements
- of the vector. Reducing @code{-} computes the first element minus each of
- the remaining elements. Reducing @code{max} computes the maximum element
- and so on. In general, reducing @code{f} over the vector @samp{[a, b, c, d]}
- produces @samp{f(f(f(a, b), c), d)}.
- X
- @kindex I V R
- @tindex rreduce
- The @kbd{I V R} [@code{rreduce}] command is similar to @kbd{V R} except
- that works from right to left through the vector. For example, plain
- @kbd{V R -} on the vector @samp{[a, b, c, d]} produces @samp{a - b - c - d}
- but @kbd{I V R -} on the same vector produces @samp{a - (b - (c - d))},
- or @samp{a - b + c - d}. This ``alternating sum'' occurs frequently
- in power series expansions.
- X
- @kindex V U
- @tindex accum
- The @kbd{V U} (@code{calc-accumulate}) [@code{accum}] command does an
- accumulation operation. Here Calc does the corresponding reduction
- operation, but instead of producing only the final result, it produces
- a vector of all the intermediate results. Accumulating @code{+} over
- the vector @samp{[a, b, c, d]} produces the vector
- @samp{[a, a + b, a + b + c, a + b + c + d]}.
- X
- @kindex I V U
- @tindex raccum
- The @kbd{I V U} [@code{raccum}] command does a right-to-left accumulation.
- For example, @kbd{I V U -} on the vector @samp{[a, b, c, d]} produces the
- vector @samp{[a - b + c - d, b - c + d, c - d, d]}.
- X
- @tindex reducea
- @tindex rreducea
- @tindex reduced
- @tindex rreduced
- As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For
- example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will
- compute @cite{a + b + c + d + e + f}. You can type @kbd{V R _} or
- @kbd{V R :} to modify this behavior. The @kbd{V R _} [@code{reducea}]
- command reduces ``across'' the matrix; it reduces each row of the matrix
- as a vector, then collects the results. Thus @kbd{V R _ +} of this
- matrix would produce @cite{[a + b + c, d + e + f]}. Similarly, @kbd{V R :}
- [@code{reduced}] reduces down; @kbd{V R : +} would produce @cite{[a + d,
- b + e, c + f]}.
- X
- @tindex reducer
- @tindex rreducer
- There is a third ``by rows'' mode for reduction that is occasionally
- useful; @kbd{V R =} [@code{reducer}] simply reduces the operator over
- the rows of the matrix themselves. Thus @kbd{V R = +} on the above
- matrix would get the same result as @kbd{V R : +}, since adding two
- row vectors is equivalent to adding their elements. But @kbd{V R = *}
- would multiply the two rows (to get a single number, their dot product),
- while @kbd{V R : *} would produce a vector of the products of the columns.
- X
- These three matrix reduction modes work with @kbd{V R} and @kbd{I V R},
- but they are not currently supported with @kbd{V U} or @kbd{I V U}.
- X
- @tindex reducec
- @tindex rreducec
- The obsolete reduce-by-columns function, @code{reducec}, is still
- supported but there is no way to get it through the @kbd{V R} command.
- X
- The commands @kbd{M-# :} and @kbd{M-# _} are equivalent to typing
- @kbd{M-# r} to grab a rectangle of data into Calc, and then typing
- @kbd{V R : +} or @kbd{V R _ +}, respectively, to sum the columns or
- rows of the matrix. @xref{Grabbing From Buffers}.
- X
- @node Nesting and Fixed Points, Generalized Products, Reducing, Reducing and Mapping
- @subsection Nesting and Fixed Points
- X
- @noindent
- @kindex H V R
- @tindex nest
- The @kbd{H V R} [@code{nest}] command applies a function to a given
- argument repeatedly. It takes two values, @samp{a} and @samp{n}, from
- the stack, where @samp{n} must be an integer. It then applies the
- function nested @samp{n} times; if the function is @samp{f} and @samp{n}
- is 3, the result is @samp{f(f(f(a)))}. The number @samp{n} may be
- negative if Calc knows an inverse for the function @samp{f}; for
- example, @samp{nest(sin, a, -2)} returns @samp{arcsin(arcsin(a))}.
- X
- @kindex H V U
- @tindex anest
- The @kbd{H V U} [@code{anest}] command is an accumulating version of
- @code{nest}: It returns a vector of @samp{n+1} values, e.g.,
- @samp{[a, f(a), f(f(a)), f(f(f(a)))]}. If @samp{n} is negative and
- @samp{F} is the inverse of @samp{f}, then the result is of the
- form @samp{[a, F(a), F(F(a)), F(F(F(a)))]}.
- X
- @kindex H I V R
- @tindex fixp
- @cindex Fixed points
- The @kbd{H I V R} [@code{fixp}] command is like @kbd{H V R}, except
- that it takes only an @samp{a} value from the stack; the function is
- applied until it reaches a ``fixed point,'' i.e., until the result
- no longer changes.
- X
- @kindex H I V U
- @tindex afixp
- The @kbd{H I V U} [@code{afixp}] command is an accumulating @code{fixp}.
- The first element of the return vector will be the initial value @samp{a};
- the last element will be the final result that would have been returned
- by @code{fixp}.
- X
- For example, 0.739085 is a fixed point of the cosine function (in radians):
- @samp{cos(0.739085) = 0.739085}. You can find this value by putting, say,
- 1.0 on the stack and typing @kbd{H I V U C}. (We use the accumulating
- version so we can see the intermediate results: @samp{[1, 0.540302, 0.857553,
- 0.65329, ...]}. With a precision of six, this command will take 36 steps
- to converge to 0.739085.)
- X
- Newton's method for finding roots is a classic example of iteration
- to a fixed point. To find the square root of five starting with an
- initial guess, Newton's method would look for a fixed point of the
- function @samp{(x + 5/x) / 2}. Putting a guess of 1 on the stack
- and typing @kbd{H I V R ' ($ + 5/$)/2 RET} quickly yields the result
- 2.23607. This is equivalent to using the @kbd{a R} (@code{calc-find-root})
- command to find a root of the equation @samp{x^2 = 5}.
- X
- These examples used numbers for @samp{a} values. Calc keeps applying
- the function until two successive results are equal to within the
- current precision. For complex numbers, both the real parts and the
- imaginary parts must be equal to within the current precision. If
- @samp{a} is a formula (say, a variable name), then the function is
- applied until two successive results are exactly the same formula.
- It is up to you to ensure that the function will eventually converge;
- if it doesn't, you may have to press @kbd{C-g} to stop the Calculator.
- X
- The algebraic @code{fixp} function takes two optional arguments, @samp{n}
- and @samp{tol}. The first is the maximum number of steps to be allowed,
- and must be either an integer or the symbol @samp{inf} (infinity, the
- default). The second is a convergence tolerance. If a tolerance is
- specified, all results during the calculation must be numbers, not
- formulas, and the iteration stops when the magnitude of the difference
- between two successive results is less than or equal to the tolerance.
- (This implies that a tolerance of zero iterates until the results are
- exactly equal.)
- X
- Putting it all together, @samp{fixp(<(# + A/#)/2>, B, 20, 1e-10)}
- computes the square root of @samp{A} given the initial guess @samp{B},
- stopping when the result is correct within the specified tolerance, or
- when 20 steps have been taken, whichever is sooner.
- X
- @node Generalized Products, , Nesting and Fixed Points, Reducing and Mapping
- @subsection Generalized Products
- X
- @kindex V O
- @pindex calc-outer-product
- @tindex outer
- The @kbd{V O} (@code{calc-outer-product}) [@code{outer}] command applies
- a given binary operator to all possible pairs of elements from two
- vectors, to produce a matrix. For example, @kbd{V O *} with @samp{[a, b]}
- and @samp{[x, y, z]} on the stack produces a multiplication table:
- @samp{[[a x, a y, a z], [b x, b y, b z]]}. Element @var{r},@var{c} of
- the result matrix is obtained by applying the operator to element @var{r}
- of the lefthand vector and element @var{c} of the righthand vector.
- X
- @kindex V I
- @pindex calc-inner-product
- @tindex inner
- The @kbd{V I} (@code{calc-inner-product}) [@code{inner}] command computes
- the generalized inner product of two vectors or matrices, given a
- ``multiplicative'' operator and an ``additive'' operator. These can each
- actually be any binary operators; if they are @samp{*} and @samp{+},
- respectively, the result is a standard matrix multiplication. Element
- @var{r},@var{c} of the result matrix is obtained by mapping the
- multiplicative operator across row @var{r} of the lefthand matrix and
- column @var{c} of the righthand matrix, and then reducing with the additive
- operator. Just as for the standard @kbd{*} command, this can also do a
- vector-matrix or matrix-vector inner product, or a vector-vector
- generalized dot product.
- X
- Since @kbd{V I} requires two operators, it prompts twice. In each case,
- you can use any of the usual methods for entering the operator. If you
- use @kbd{$} twice to take both operator formulas from the stack, the
- first (multiplicative) operator is taken from the top of the stack
- and the second (additive) operator is taken from second-to-top.
- X
- @node Vector and Matrix Formats, , Reducing and Mapping, Matrix Functions
- @section Vector and Matrix Display Formats
- X
- @noindent
- Commands for controlling vector and matrix display use the @kbd{v} prefix
- instead of the usual @kbd{d} prefix. But they are display modes; in
- particular, they are influenced by the @kbd{I} and @kbd{H} prefix keys
- in the same way (@pxref{Display Modes}). Matrix display is also
- influenced by the @kbd{d O} (@code{calc-flat-language}) mode;
- @pxref{Normal Language Modes}.
- X
- @kindex v <
- @pindex calc-matrix-left-justify
- @kindex v =
- @pindex calc-matrix-center-justify
- @kindex v >
- @pindex calc-matrix-right-justify
- The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >}
- (@code{calc-matrix-right-justify}), and @kbd{v =}
- (@code{calc-matrix-center-justify}) control whether matrix elements
- are justified to the left, right, or center of their columns.@refill
- X
- @kindex v [
- @pindex calc-vector-brackets
- @kindex v @{
- @pindex calc-vector-braces
- @kindex v (
- @pindex calc-vector-parens
- The @kbd{v [} (@code{calc-vector-brackets}) command turns the square
- brackets that surround vectors and matrices displayed in the stack on
- and off. The @kbd{v @{} (@code{calc-vector-braces}) and @kbd{v (}
- (@code{calc-vector-parens}) commands use curly braces or parentheses,
- respectively, instead of square brackets. For example, @kbd{v @{} might
- be used in preparation for yanking a matrix into a buffer running
- Mathematica. (In fact, the Mathematica language mode uses this mode;
- @pxref{Mathematica Language Mode}.) Note that, regardless of the
- display mode, either brackets or braces may be used to enter vectors,
- and parentheses may never be used for this purpose.@refill
- X
- @kindex v ]
- @pindex calc-matrix-brackets
- The @kbd{v ]} (@code{calc-matrix-brackets}) command controls the
- ``big'' style display of matrices. It prompts for a string of code
- letters; currently implemented letters are @code{R}, which enables
- brackets on each row of the matrix; @code{O}, which enables outer
- brackets in opposite corners of the matrix; and @code{C}, which
- enables commas or semicolons at the ends of all rows but the last.
- The default format is @samp{RO}. (Before Calc 2.00, the format
- was fixed at @samp{ROC}.) Here are some example matrices:
- X
- @group
- @example
- [ [ 123, 0, 0 ] [ [ 123, 0, 0 ],
- X [ 0, 123, 0 ] [ 0, 123, 0 ],
- X [ 0, 0, 123 ] ] [ 0, 0, 123 ] ]
- X
- X RO ROC
- X
- @end example
- @end group
- @noindent
- @group
- @example
- X [ 123, 0, 0 [ 123, 0, 0 ;
- X 0, 123, 0 0, 123, 0 ;
- X 0, 0, 123 ] 0, 0, 123 ]
- X
- X O OC
- X
- @end example
- @end group
- @noindent
- @group
- @example
- X [ 123, 0, 0 ] 123, 0, 0
- X [ 0, 123, 0 ] 0, 123, 0
- X [ 0, 0, 123 ] 0, 0, 123
- X
- X R @r{blank}
- @end example
- @end group
- X
- @noindent
- Note that of the formats shown here, @samp{RO}, @samp{ROC}, and
- @samp{OC} are all recognized as matrices during reading, while
- the others are useful for display only.
- X
- @kindex v ,
- @pindex calc-vector-commas
- The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and
- off in vector and matrix display.@refill
- X
- In vectors of length one, and in all vectors when commas have been
- turned off, Calc adds extra parentheses around formulas that might
- otherwise be ambiguous. For example, @samp{[a b]} could be a vector
- of the one formula @samp{a b}, or it could be a vector of two
- variables with commas turned off. Calc will display the former
- case as @samp{[(a b)]}. You can disable these extra parentheses
- (to make the output less cluttered at the expense of allowing some
- ambiguity) by adding the letter @code{P} to the control string you
- give to @kbd{v ]} (as described above).
- X
- @kindex v .
- @pindex calc-full-vectors
- The @kbd{v .} (@code{calc-full-vectors}) command turns abbreviated
- display of long vectors on and off. In this mode, vectors of six
- or more elements, or matrices of six or more rows or columns, will
- be displayed in an abbreviated form that displays only the first
- three elements and the last element: @samp{[a, b, c, ..., z]}.
- When very large vectors are involved this will substantially
- improve Calc's display speed.
- X
- @kindex t .
- @pindex calc-full-trail-vectors
- The @kbd{t .} (@code{calc-full-trail-vectors}) command controls a
- similar mode for recording vectors in the Trail. If you turn on
- this mode, vectors of six or more elements and matrices of six or
- more rows or columns will be abbreviated when they are put in the
- Trail. The @kbd{t y} (@code{calc-trail-yank}) command will be
- unable to recover those vectors. If you are working with very
- large vectors, this mode will improve the speed of all operations
- that involve the trail.
- X
- @kindex v /
- @pindex calc-break-vectors
- The @kbd{v /} (@code{calc-break-vectors}) command turns multi-line
- vector display on and off. Normally, matrices are displayed with one
- row per line but all other types of vectors are displayed in a single
- line. This mode causes all vectors, whether matrices or not, to be
- displayed with a single element per line. Sub-vectors within the
- vectors will still use the normal linear form.
- X
- @node Algebra, Units, Matrix Functions, Top
- @chapter Algebra
- X
- @noindent
- This section covers the Calc features that help you work with
- algebraic formulas. First, the general sub-formula selection
- mechanism is described; this works in conjunction with any Calc
- commands. Then, commands for specific algebraic operations are
- described. Finally, the flexible @dfn{rewrite rule} mechanism
- is discussed.
- X
- The algebraic commands use the @kbd{a} key prefix; selection
- commands use the @kbd{j} (for ``just a letter that wasn't used
- for anything else'') prefix.
- X
- @xref{Editing Stack Entries}, to see how to manipulate formulas
- using regular Emacs editing commands.@refill
- X
- When doing algebraic work, you may find several of the Calculator's
- modes to be helpful, including algebraic-simplification mode (@kbd{m A})
- or no-simplification mode (@kbd{m O}),
- algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
- symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions
- of these modes. You may also wish to select ``big'' display mode (@kbd{d B}).
- @xref{Normal Language Modes}.@refill
- X
- @menu
- * Selecting Subformulas::
- * Algebraic Manipulation::
- * Simplifying Formulas::
- * Polynomials::
- * Calculus::
- * Solving Equations::
- * Numerical Solutions::
- * Curve Fitting::
- * Summations::
- * Logical Operations::
- * Rewrite Rules::
- @end menu
- X
- @node Selecting Subformulas, Algebraic Manipulation, Algebra, Algebra
- @section Selecting Sub-Formulas
- X
- @noindent
- @cindex Selections
- @cindex Sub-formulas
- @cindex Parts of formulas
- When working with an algebraic formula it is often necessary to
- manipulate a portion of the formula rather than the formula as a
- whole. Calc allows you to ``select'' a portion of any formula on
- the stack. Commands which would normally operate on that stack
- entry will now operate only on the sub-formula, leaving the
- surrounding part of the stack entry alone.
- X
- One common non-algebraic use for selection involves vectors. To work
- on one element of a vector in-place, simply select that element as a
- ``sub-formula'' of the vector.
- X
- @menu
- * Making Selections::
- * Changing Selections::
- * Displaying Selections::
- * Operating on Selections::
- * Rearranging with Selections::
- @end menu
- X
- @node Making Selections, Changing Selections, Selecting Subformulas, Selecting Subformulas
- @subsection Making Selections
- X
- @noindent
- @kindex j s
- @pindex calc-select-here
- To select a sub-formula, move the Emacs cursor to any character in that
- sub-formula, and press @kbd{j s} (@code{calc-select-here}). Calc will
- highlight the smallest portion of the formula that contains that
- character. By default the sub-formula is highlighted by blanking out
- all of the rest of the formula with dots. Selection works in any
- display mode but is perhaps easiest in ``big'' (@kbd{d B}) mode.
- Suppose you enter the following formula:
- X
- @group
- @smallexample
- X 3 ___
- X (a + b) + V c
- 1: ---------------
- X 2 x + 1
- @end smallexample
- @end group
- X
- @noindent
- (by typing @kbd{' ((a+b)^3 + sqrt(c)) / (2x+1)}). If you move the
- cursor to the letter @samp{b} and press @kbd{j s}, the display changes
- to
- X
- @group
- @smallexample
- X . ...
- X .. . b. . . .
- 1* ...............
- X . . . .
- @end smallexample
- @end group
- X
- @noindent
- Every character not part of the sub-formula @samp{b} has been changed
- to a dot. The @samp{*} next to the line number is to remind you that
- the formula has a portion of it selected. (In this case, it's very
- obvious, but it might not always be. If Embedded Mode is enabled,
- the word @samp{Sel} also appears in the mode line because the stack
- may not be visible. @pxref{Embedded Mode}.)
- X
- If you had instead placed the cursor on the parenthesis immediately to
- the right of the @samp{b}, the selection would have been:
- X
- @group
- @smallexample
- X . ...
- X (a + b) . . .
- 1* ...............
- X . . . .
- @end smallexample
- @end group
- X
- @noindent
- The portion selected is always large enough to be considered a complete
- formula all by itself, so selecting the parenthesis selects the whole
- formula that it encloses. Putting the cursor on the the @samp{+} sign
- would have had the same effect.
- X
- (Strictly speaking, the Emacs cursor is really the manifestation of
- the Emacs ``point,'' which is a position @emph{between} two characters
- in the buffer. So purists would say that Calc selects the smallest
- sub-formula which contains the character to the right of ``point.'')
- X
- If you supply a numeric prefix argument @var{n}, the selection is
- expanded to the @var{n}th enclosing sub-formula. Thus, positioning
- the cursor on the @samp{b} and typing @kbd{C-u 1 j s} will select
- @samp{a + b}; typing @kbd{C-u 2 j s} will select @samp{(a + b)^3},
- and so on.
- X
- If the cursor is not on any part of the formula, or if you give a
- numeric prefix that is too large, the entire formula is selected.
- X
- If the cursor is on the @samp{.} line that marks the top of the stack
- (i.e., its normal ``rest position''), this command selects the entire
- formula at stack level 1. Most selection commands similarly operate
- on the formula at the top of the stack if you haven't positioned the
- cursor on any stack entry.
- X
- @kindex j a
- @pindex calc-select-additional
- The @kbd{j a} (@code{calc-select-additional}) command enlarges the
- current selection to encompass the cursor. To select the smallest
- sub-formula defined by two different points, move to the first and
- press @kbd{j s}, then move to the other and press @kbd{j a}. This
- is roughly analogous to using @code{set-mark-command} to select the
- two ends of a region of text during normal Emacs editing.
- X
- @kindex j o
- @pindex calc-select-once
- The @kbd{j o} (@code{calc-select-once}) command selects a formula in
- exactly the same way as @kbd{j s}, except that the selection will
- last only as long as the next command that uses it. For example,
- @kbd{j o 1 +} is a handy way to add one to the sub-formula indicated
- by the cursor.
- X
- (A somewhat more precise definition: The @kbd{j o} command sets a flag
- such that the next command involving selected stack entries will clear
- the selections on those stack entries afterwards. All other selection
- commands except @kbd{j a} and @kbd{j O} clear this flag.)
- X
- @kindex j S
- @kindex j O
- @pindex calc-select-here-maybe
- @pindex calc-select-once-maybe
- The @kbd{j S} (@code{calc-select-here-maybe}) and @kbd{j O}
- (@code{calc-select-once-maybe}) commands are equivalent to @kbd{j s}
- and @kbd{j o}, respectively, except that if the formula already
- has a selection they have no effect. This is analogous to the
- behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection};
- @pxref{Selections with Rewrite Rules}) and is mainly intended to be
- used in keyboard macros that implement your own selection-oriented
- commands.@refill
- X
- Selection of sub-formulas normally treats associative terms like
- @samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula.
- If you place the cursor anywhere inside @samp{a + b - c + d} except
- on one of the variable names and use @kbd{j s}, you will select the
- entire four-term sum.
- X
- @kindex j b
- @pindex calc-break-selections
- The @kbd{j b} (@code{calc-break-selections}) command controls a mode
- in which the ``deep structure'' of these associative formulas shows
- through. Calc actually stores the above formulas as @samp{((a + b) - c) + d}
- and @samp{x * (y * z)} (note that for certain obscure reasons, Calc
- treats multiplication as right-associative). Once you have enabled
- @kbd{j b} mode, selecting with the cursor on the @samp{-} sign would
- only select the @samp{a + b - c} portion, which makes sense when the
- deep structure of the sum is considered. There is no way to select
- the @samp{b - c + d} portion; although this might initially look
- like just as legitimate a sub-formula as @samp{a + b - c}, the deep
- structure shows that it isn't. The @kbd{d U} command can be used
- to view the deep structure of any formula (@pxref{Normal Language Modes}).
- X
- When @kbd{j b} mode has not been enabled, the deep structure is
- generally hidden by the selection commands---what you see is what
- you get.
- X
- @kindex j u
- @pindex calc-unselect
- The @kbd{j u} (@code{calc-unselect}) command unselects the formula
- that the cursor is on. If there was no selection in the formula,
- this command has no effect. With a numeric prefix argument, it
- unselects that stack element rather than using the cursor position.
- X
- @kindex j c
- @pindex calc-clear-selections
- The @kbd{j c} (@code{calc-clear-selections}) command unselects all
- stack elements.
- X
- @node Changing Selections, Displaying Selections, Making Selections, Selecting Subformulas
- @subsection Changing Selections
- X
- @noindent
- @kindex j m
- @pindex calc-select-more
- Once you have selected a sub-formula, you can expand it using the
- @w{@kbd{j m}} (@code{calc-select-more}) command. If @samp{a + b} is
- selected, pressing @w{@kbd{j m}} repeatedly works as follows:
- X
- @group
- @smallexample
- X 3 ... 3 ___ 3 ___
- X (a + b) . . . (a + b) + V c (a + b) + V c
- 1* ............... 1* ............... 1* ---------------
- X . . . . . . . . 2 x + 1
- @end smallexample
- @end group
- X
- @noindent
- In the last example, the entire formula is selected. This is roughly
- the same as having no selection at all, but because there are subtle
- differences the @samp{*} character is still there on the line number.
- X
- With a numeric prefix argument @var{n}, @kbd{j m} expands @var{n}
- times (or until the entire formula is selected). Note that @kbd{j s}
- with argument @var{n} is equivalent to plain @kbd{j s} followed by
- @kbd{j m} with argument @var{n}. If @w{@kbd{j m}} is used when there
- is no current selection, it is equivalent to @w{@kbd{j s}}.
- X
- Even though @kbd{j m} does not explicitly use the location of the
- cursor within the formula, it nevertheless uses the cursor to determine
- which stack element to operate on. As usual, @kbd{j m} when the cursor
- is not on any stack element operates on the top stack element.
- X
- @kindex j l
- @pindex calc-select-less
- The @kbd{j l} (@code{calc-select-less}) command reduces the current
- selection around the cursor position. That is, it selects the
- immediate sub-formula of the current selection which contains the
- cursor, the opposite of @kbd{j m}. If the cursor is not inside the
- current selection, the command de-selects the formula.
- X
- @kindex j 1-9
- @pindex calc-select-part
- The @kbd{j 1} through @kbd{j 9} (@code{calc-select-part}) commands
- select the @var{n}th sub-formula of the current selection. They are
- like @kbd{j l} (@code{calc-select-less}) except they use counting
- rather than the cursor position to decide which sub-formula to select.
- For example, if the current selection is @kbd{a + b + c} or
- @kbd{f(a, b, c)} or @kbd{[a, b, c]}, then @kbd{j 1} selects @samp{a},
- @kbd{j 2} selects @samp{b}, and @kbd{j 3} selects @samp{c}; in each of
- these cases, @kbd{j 4} through @kbd{j 9} would be errors.
- X
- If there is no current selection, @kbd{j 1} through @kbd{j 9} select
- the @var{n}th top-level sub-formula. (In other words, they act as if
- the entire stack entry were selected first.) To select the @var{n}th
- sub-formula where @var{n} is greater than nine, you must instead invoke
- @w{@kbd{j 1}} with @var{n} as a numeric prefix argument.@refill
- X
- @kindex j n
- @kindex j p
- @pindex calc-select-next
- @pindex calc-select-previous
- The @kbd{j n} (@code{calc-select-next}) and @kbd{j p}
- (@code{calc-select-previous}) commands change the current selection
- to the next or previous sub-formula at the same level. For example,
- if @samp{b} is selected in @samp{2 + a*b*c + x}, then @kbd{j n}
- selects @samp{c}. Further @kbd{j n} commands would be in error because,
- even though there is something to the right of @samp{c} (namely, @samp{x}),
- it is not at the same level; in this case, it is not a term of the
- same product as @samp{b} and @samp{c}. However, @kbd{j m} (to select
- the whole product @samp{a*b*c} as a term of the sum) followed by
- @w{@kbd{j n}} would successfully select the @samp{x}.
- X
- Similarly, @kbd{j p} moves the selection from the @samp{b} in this
- sample formula to the @samp{a}. Both commands accept numeric prefix
- arguments to move several steps at a time.
- X
- It is interesting to compare Calc's selection commands with the
- Emacs Info system's commands for navigating through hierarchically
- organized documentation. Calc's @kbd{j n} command is completely
- analogous to Info's @kbd{n} command. Likewise, @kbd{j p} maps to
- @kbd{p}, @kbd{j 2} maps to @kbd{2}, and Info's @kbd{u} is like @kbd{j m}.
- (Note that @kbd{j u} stands for @code{calc-unselect}, not ``up''.)
- The Info @kbd{m} command is somewhat similar to Calc's @kbd{j s} and
- @kbd{j l}; in each case, you can jump directly to a sub-component
- of the hierarchy simply by pointing to it with the cursor.
- X
- @node Displaying Selections, Operating on Selections, Changing Selections, Selecting Subformulas
- @subsection Displaying Selections
- X
- @noindent
- @kindex j d
- @pindex calc-show-selections
- The @kbd{j d} (@code{calc-show-selections}) command controls how
- selected sub-formulas are displayed. One of the alternatives is
- illustrated in the above examples; if we press @kbd{j d} we switch
- to the other style in which the selected portion itself is obscured
- by @samp{#} signs:
- X
- @group
- @smallexample
- X 3 ... # ___
- X (a + b) . . . ## # ## + V c
- 1* ............... 1* ---------------
- X . . . . 2 x + 1
- @end smallexample
- @end group
- X
- @node Operating on Selections, Rearranging with Selections, Displaying Selections, Selecting Subformulas
- @subsection Operating on Selections
- X
- @noindent
- Once a selection is made, all Calc commands that manipulate items
- on the stack will operate on the selected portions of the items
- instead. (Note that several stack elements may have selections
- at once, though there can be only one selection at a time in any
- given stack element.)
- X
- @kindex j e
- @pindex calc-enable-selections
- The @kbd{j e} (@code{calc-enable-selections}) command disables the
- effect that selections have on Calc commands. The current selections
- still exist, but Calc commands operate on whole stack elements anyway.
- This mode can be identified by the fact that the @samp{*} markers on
- the line numbers are gone, even though selections are visible. To
- reactivate the selections, press @kbd{j e} again.
- X
- To extract a sub-formula as a new formula, simply press @key{RET}.
- This normally duplicates the top stack element; here it duplicates
- only the selected portion of that element.
- X
- To replace a sub-formula with something different, you can enter the
- new value onto the stack and press @key{TAB}. This normally exchanges
- the top two stack elements; here it swaps the value you entered into
- the selected portion of the formula, returning the old selected
- portion to the top of the stack.
- X
- @group
- @smallexample
- X 3 ... ... ___
- X (a + b) . . . 17 x y . . . 17 x y + V c
- 2* ............... 2* ............. 2: -------------
- X . . . . . . . . 2 x + 1
- X
- X 3 3
- 1: 17 x y 1: (a + b) 1: (a + b)
- @end smallexample
- @end group
- X
- In this example we select a sub-formula of our original example,
- enter a new formula, @key{TAB} it into place, then deselect to see
- the complete, edited formula.
- X
- If you want to swap whole formulas around even though they contain
- selections, just use @kbd{j e} before and after.
- X
- @kindex j '
- @pindex calc-enter-selection
- The @kbd{j '} (@code{calc-enter-selection}) command is another way
- to replace a selected sub-formula. This command does an algebraic
- entry just like the regular @kbd{'} key. When you press @key{RET},
- the formula you type replaces the original selection. You can use
- the @samp{$} symbol in the formula to refer to the original
- selection. If there is no selection in the formula under the cursor,
- the cursor is used to make a temporary selection for the purposes of
- the command. Thus, to change a term of a formula, all you have to
- do is move the Emacs cursor to that term and press @kbd{j '}.
- X
- @kindex j `
- @pindex calc-edit-selection
- The @kbd{j `} (@code{calc-edit-selection}) command is a similar
- analogue of the @kbd{`} (@code{calc-edit}) command. It edits the
- selected sub-formula in a separate buffer. If there is no
- selection, it edits the sub-formula indicated by the cursor.
- X
- To delete a sub-formula, press @key{DEL}. This generally replaces
- the sub-formula with the constant zero, but in a few suitable contexts
- it uses the constant one instead. The @key{DEL} key automatically
- deselects and re-simplifies the entire formula afterwards. Thus:
- X
- @group
- @smallexample
- X ###
- X 17 x y + # # 17 x y 17 # y 17 y
- 1* ------------- 1: ------- 1* ------- 1: -------
- X 2 x + 1 2 x + 1 2 x + 1 2 x + 1
- @end smallexample
- @end group
- X
- In this example, we first delete the @samp{sqrt(c)} term; Calc
- accomplishes this by replacing @samp{sqrt(c)} with zero and
- resimplifying. We then delete the @kbd{x} in the numerator;
- since this is part of a product, Calc replaces it with @samp{1}
- and resimplifies.
- X
- If you select an element of a vector and press @key{DEL}, that
- element is deleted from the vector. If you delete one side of
- an equation or inequality, only the opposite side remains.
- X
- @kindex j DEL
- @pindex calc-del-selection
- The @kbd{j @key{DEL}} (@code{calc-del-selection}) command is like
- @key{DEL} but with the auto-selecting behavior of @kbd{j '} and
- @kbd{j `}. It deletes the selected portion of the formula
- indicated by the cursor, or, in the absence of a selection, it
- deletes the sub-formula indicated by the cursor position.
- X
- @kindex j RET
- @pindex calc-grab-selection
- (There is also an auto-selecting @kbd{j @key{RET}} (@code{calc-copy-selection})
- command.)
- X
- Normal arithmetic operations also apply to sub-formulas. Here we
- select the denominator, press @kbd{5 -} to subtract five from the
- denominator, press @kbd{n} to negate the denominator, then
- press @kbd{Q} to take the square root.
- X
- @group
- @smallexample
- X .. . .. . .. . .. .
- 1* ....... 1* ....... 1* ....... 1* ..........
- X 2 x + 1 2 x - 4 4 - 2 x _________
- X V 4 - 2 x
- @end smallexample
- @end group
- X
- Certain types of operations on selections are not allowed. For
- example, for an arithmetic function like @kbd{-} no more than one of
- the arguments may be a selected sub-formula. (As the above example
- shows, the result of the subtraction is spliced back into the argument
- which had the selection; if there were more than one selection involved,
- this would not be well-defined.) If you try to subtract two selections,
- the command will abort with an error message.
- X
- Operations on sub-formulas sometimes leave the formula as a whole
- in an ``un-natural'' state. Consider negating the @samp{2 x} term
- of our sample formula by selecting it and pressing @kbd{n}
- (@code{calc-change-sign}).@refill
- X
- @group
- @smallexample
- X .. . .. .
- 1* .......... 1* ...........
- X ......... ..........
- X . . . 2 x . . . -2 x
- @end smallexample
- @end group
- X
- Unselecting the sub-formula reveals that the minus sign, which would
- normally have cancelled out with the subtraction automatically, has
- not been able to do so because the subtraction was not part of the
- selected portion. Pressing @kbd{=} (@code{calc-evaluate}) or doing
- any other mathematical operation on the whole formula will cause it
- to be simplified.
- X
- @group
- @smallexample
- X 17 y 17 y
- 1: ----------- 1: ----------
- X __________ _________
- X V 4 - -2 x V 4 + 2 x
- @end smallexample
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 44'
- echo 'File calc.texinfo is continued in part 45'
- echo 45 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-